package kr.saeildamil.androidstudy.ch08;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class HandlerOrder extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = new MyView(this);
		
		//리스너 -1순위
		view.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == MotionEvent.ACTION_DOWN){
					Toast.makeText(HandlerOrder.this, "Listener:Touch Event Received", Toast.LENGTH_SHORT).show();
					//return true;
				}
				return false;
			}
		});
		setContentView(view);
	}
	
	public class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		
		//뷰의 콜백 메서드 -순위
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			if(event.getAction() == MotionEvent.ACTION_DOWN){
				Toast.makeText(HandlerOrder.this, "View:Touch Event Received", Toast.LENGTH_SHORT).show();
				//return true;
			}
			return false;
		}
	}

	//액티비티의 콜백 메서드
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			Toast.makeText(HandlerOrder.this, "Activity:Touch Event Received", Toast.LENGTH_SHORT).show();
			return true;
		}
		return false;
	}
	
	
	
	
	
}
